cmake_minimum_required(VERSION 3.1...3.16)

if(${CMAKE_VERSION} VERSION_LESS 3.12)
  cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()

if(UNIX AND NOT APPLE)
  set(LINUX TRUE)
endif()

project(msbench VERSION 0.2
  DESCRIPTION "Code for managing maxsat benchmark collection"
  LANGUAGES CXX)

include(cmake/default_project_settings.cmake)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

set(EXECS std_wcnf verify_soln to_cnf to_old_fmt std_wcnf_blo) 

add_executable(std_wcnf src/std_wcnf.cc)
add_executable(verify_soln src/verify_soln.cc)
add_executable(to_cnf src/to_cnf.cc)
add_executable(to_old_fmt src/to_old_fmt.cc)
add_executable(std_wcnf_blo EXCLUDE_FROM_ALL src/std_wcnf.cc)

# compiler settings
include(cmake/compiler_warnings.cmake)

target_include_directories(std_wcnf_blo PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} cadical)
foreach(exec ${EXECS})
  target_sources(${exec} PRIVATE src/Wcnf.cc src/sys_utils.cc src/zfstream.cc)
  if(LINUX)
    set_target_properties(${exec} PROPERTIES LINK_FLAGS "--static")
  endif()
  set_compiler_warnings(${exec})
  target_compile_features(${exec} PRIVATE cxx_std_14)
  target_link_libraries(${exec} PRIVATE z)
endforeach()
target_compile_definitions(std_wcnf_blo PRIVATE BLO_TOP)
target_link_libraries(std_wcnf_blo PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/cadical/libcadical.a)

option(ENABLE_IPO "Enable Iterprocedural Optimization" ON)
message(STATUS "Compiler: \"${CMAKE_CXX_COMPILER_ID}\"")
     
if(ENABLE_IPO)
  if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
    foreach(exec ${EXECS})
     target_compile_options(${exec} PRIVATE -flto)
     target_link_options(${exec} PRIVATE -flto)
     endforeach()
  endif()
endif()

install(TARGETS verify_soln std_wcnf to_cnf to_old_fmt DESTINATION "${CMAKE_SOURCE_DIR}/..")
